<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户id" prop="uid">
      <el-input v-model="dataForm.uid" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="品牌" prop="brand">
      <el-input v-model="dataForm.brand" placeholder="品牌"></el-input>
    </el-form-item>
    <el-form-item label="类别" prop="type">
      <el-input v-model="dataForm.type" placeholder="类别"></el-input>
    </el-form-item>
    <el-form-item label="sku" prop="sku">
      <el-input v-model="dataForm.sku" placeholder="sku"></el-input>
    </el-form-item>
    <el-form-item label="颜色" prop="color">
      <el-input v-model="dataForm.color" placeholder="颜色"></el-input>
    </el-form-item>
    <el-form-item label="尺寸" prop="size">
      <el-input v-model="dataForm.size" placeholder="尺寸"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="sex">
      <el-input v-model="dataForm.sex" placeholder="性别"></el-input>
    </el-form-item>
    <el-form-item label="价格" prop="price">
      <el-input v-model="dataForm.price" placeholder="价格"></el-input>
    </el-form-item>
    <el-form-item label="到货时间" prop="reciveTime">
      <el-input v-model="dataForm.reciveTime" placeholder="到货时间"></el-input>
    </el-form-item>
    <el-form-item label="描述" prop="description">
      <el-input v-model="dataForm.description" placeholder="描述"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createdAt">
      <el-input v-model="dataForm.createdAt" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updatedAt">
      <el-input v-model="dataForm.updatedAt" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="客户名称" prop="fullName">
      <el-input v-model="dataForm.fullName" placeholder="客户名称"></el-input>
    </el-form-item>
    <el-form-item label="省份" prop="province">
      <el-input v-model="dataForm.province" placeholder="省份"></el-input>
    </el-form-item>
    <el-form-item label="密语" prop="miyu">
      <el-input v-model="dataForm.miyu" placeholder="密语"></el-input>
    </el-form-item>
    <el-form-item label="价格区间" prop="priceArea">
      <el-input v-model="dataForm.priceArea" placeholder="价格区间"></el-input>
    </el-form-item>
    <el-form-item label="数量" prop="number">
      <el-input v-model="dataForm.number" placeholder="数量"></el-input>
    </el-form-item>
    <el-form-item label="标题" prop="title">
      <el-input v-model="dataForm.title" placeholder="标题"></el-input>
    </el-form-item>
    <el-form-item label="标志" prop="flag">
      <el-input v-model="dataForm.flag" placeholder="标志"></el-input>
    </el-form-item>
    <el-form-item label="发布的位置" prop="location">
      <el-input v-model="dataForm.location" placeholder="发布的位置"></el-input>
    </el-form-item>
    <el-form-item label="删除状态标记：null为未删除，有时间表示已删除" prop="deletedAt">
      <el-input v-model="dataForm.deletedAt" placeholder="删除状态标记：null为未删除，有时间表示已删除"></el-input>
    </el-form-item>
    <el-form-item label="达人笔记相应的标签id" prop="labelId">
      <el-input v-model="dataForm.labelId" placeholder="达人笔记相应的标签id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          uid: '',
          brand: '',
          type: '',
          sku: '',
          color: '',
          size: '',
          sex: '',
          price: '',
          reciveTime: '',
          description: '',
          createdAt: '',
          updatedAt: '',
          status: '',
          address: '',
          phone: '',
          fullName: '',
          province: '',
          miyu: '',
          priceArea: '',
          number: '',
          title: '',
          flag: '',
          location: '',
          deletedAt: '',
          labelId: ''
        },
        dataRule: {
          uid: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          brand: [
            { required: true, message: '品牌不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类别不能为空', trigger: 'blur' }
          ],
          sku: [
            { required: true, message: 'sku不能为空', trigger: 'blur' }
          ],
          color: [
            { required: true, message: '颜色不能为空', trigger: 'blur' }
          ],
          size: [
            { required: true, message: '尺寸不能为空', trigger: 'blur' }
          ],
          sex: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '价格不能为空', trigger: 'blur' }
          ],
          reciveTime: [
            { required: true, message: '到货时间不能为空', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '描述不能为空', trigger: 'blur' }
          ],
          createdAt: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updatedAt: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '手机号不能为空', trigger: 'blur' }
          ],
          fullName: [
            { required: true, message: '客户名称不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省份不能为空', trigger: 'blur' }
          ],
          miyu: [
            { required: true, message: '密语不能为空', trigger: 'blur' }
          ],
          priceArea: [
            { required: true, message: '价格区间不能为空', trigger: 'blur' }
          ],
          number: [
            { required: true, message: '数量不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '标题不能为空', trigger: 'blur' }
          ],
          flag: [
            { required: true, message: '标志不能为空', trigger: 'blur' }
          ],
          location: [
            { required: true, message: '发布的位置不能为空', trigger: 'blur' }
          ],
          deletedAt: [
            { required: true, message: '删除状态标记：null为未删除，有时间表示已删除不能为空', trigger: 'blur' }
          ],
          labelId: [
            { required: true, message: '达人笔记相应的标签id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/biz/publishCustomers/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.uid = data.publishCustomers.uid
                this.dataForm.brand = data.publishCustomers.brand
                this.dataForm.type = data.publishCustomers.type
                this.dataForm.sku = data.publishCustomers.sku
                this.dataForm.color = data.publishCustomers.color
                this.dataForm.size = data.publishCustomers.size
                this.dataForm.sex = data.publishCustomers.sex
                this.dataForm.price = data.publishCustomers.price
                this.dataForm.reciveTime = data.publishCustomers.reciveTime
                this.dataForm.description = data.publishCustomers.description
                this.dataForm.createdAt = data.publishCustomers.createdAt
                this.dataForm.updatedAt = data.publishCustomers.updatedAt
                this.dataForm.status = data.publishCustomers.status
                this.dataForm.address = data.publishCustomers.address
                this.dataForm.phone = data.publishCustomers.phone
                this.dataForm.fullName = data.publishCustomers.fullName
                this.dataForm.province = data.publishCustomers.province
                this.dataForm.miyu = data.publishCustomers.miyu
                this.dataForm.priceArea = data.publishCustomers.priceArea
                this.dataForm.number = data.publishCustomers.number
                this.dataForm.title = data.publishCustomers.title
                this.dataForm.flag = data.publishCustomers.flag
                this.dataForm.location = data.publishCustomers.location
                this.dataForm.deletedAt = data.publishCustomers.deletedAt
                this.dataForm.labelId = data.publishCustomers.labelId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/biz/publishCustomers/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'uid': this.dataForm.uid,
                'brand': this.dataForm.brand,
                'type': this.dataForm.type,
                'sku': this.dataForm.sku,
                'color': this.dataForm.color,
                'size': this.dataForm.size,
                'sex': this.dataForm.sex,
                'price': this.dataForm.price,
                'reciveTime': this.dataForm.reciveTime,
                'description': this.dataForm.description,
                'createdAt': this.dataForm.createdAt,
                'updatedAt': this.dataForm.updatedAt,
                'status': this.dataForm.status,
                'address': this.dataForm.address,
                'phone': this.dataForm.phone,
                'fullName': this.dataForm.fullName,
                'province': this.dataForm.province,
                'miyu': this.dataForm.miyu,
                'priceArea': this.dataForm.priceArea,
                'number': this.dataForm.number,
                'title': this.dataForm.title,
                'flag': this.dataForm.flag,
                'location': this.dataForm.location,
                'deletedAt': this.dataForm.deletedAt,
                'labelId': this.dataForm.labelId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
